load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test", "rust_test_suite")
load("//bazel:defs.bzl", "rust_bench")

package(default_visibility = [
    "//rs/certification/test-utils:__subpackages__",
    "//rs/crypto:__subpackages__",
    "//rs/validator/http_request_test_utils:__subpackages__",
])

DEPENDENCIES = [
    # Keep sorted.
    "//rs/crypto/internal/crypto_lib/bls12_381/type",
    "//rs/crypto/internal/crypto_lib/seed",
    "//rs/crypto/internal/crypto_lib/types",
    "//rs/crypto/secrets_containers",
    "//rs/crypto/sha2",
    "//rs/types/types",
    "@crate_index//:base64",
    "@crate_index//:cached",
    "@crate_index//:hex",
    "@crate_index//:parking_lot",
    "@crate_index//:rand",
    "@crate_index//:rand_chacha",
    "@crate_index//:serde",
    "@crate_index//:serde_bytes",
    "@crate_index//:serde_cbor",
    "@crate_index//:subtle",
    "@crate_index//:zeroize",
]

MACRO_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:strum_macros",
]

DEV_DEPENDENCIES = [
    # Keep sorted.
    "//rs/crypto/internal/test_vectors",
    "//rs/crypto/test_utils/reproducible_rng",
    "@crate_index//:proptest",
    "@crate_index//:strum",
]

MACRO_DEV_DEPENDENCIES = [
    # Keep sorted.
    "@crate_index//:proptest-derive",
]

rust_library(
    name = "bls12_381",
    srcs = glob(["src/**"]),
    crate_name = "ic_crypto_internal_threshold_sig_bls12381",
    proc_macro_deps = MACRO_DEPENDENCIES,
    version = "0.9.0",
    deps = DEPENDENCIES,
)

rust_test(
    name = "ic_crypto_internal_threshold_sig_bls12_381_test",
    crate = ":bls12_381",
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = DEPENDENCIES + DEV_DEPENDENCIES,
)

rust_test_suite(
    name = "internal_threshold_sig_bls12_381_integration",
    srcs = glob(["tests/**/*.rs"]),
    compile_data = glob(["tests/data/*"]),
    proc_macro_deps = MACRO_DEPENDENCIES + MACRO_DEV_DEPENDENCIES,
    deps = [":bls12_381"] + DEPENDENCIES + DEV_DEPENDENCIES,
)

rust_bench(
    name = "bls_bench",
    testonly = True,
    srcs = ["benches/bls.rs"],
    deps = [
        # Keep sorted.
        ":bls12_381",
        "//rs/crypto/internal/crypto_lib/bls12_381/type",
        "//rs/crypto/internal/crypto_lib/types",
        "//rs/crypto/test_utils/reproducible_rng",
        "@crate_index//:criterion",
        "@crate_index//:rand",
    ],
)

rust_bench(
    name = "dlog_bench",
    testonly = True,
    srcs = ["benches/dlog.rs"],
    deps = [
        # Keep sorted.
        ":bls12_381",
        "//rs/crypto/internal/crypto_lib/bls12_381/type",
        "//rs/crypto/test_utils/reproducible_rng",
        "@crate_index//:criterion",
        "@crate_index//:rand",
    ],
)

rust_bench(
    name = "fs_nidkg_bench",
    testonly = True,
    srcs = ["benches/fs_nidkg.rs"],
    deps = [
        # Keep sorted.
        ":bls12_381",
        "//rs/crypto/internal/crypto_lib/bls12_381/type",
        "//rs/crypto/internal/crypto_lib/seed",
        "@crate_index//:criterion",
    ],
)

rust_bench(
    name = "zk_bench",
    testonly = True,
    srcs = ["benches/zk.rs"],
    deps = [
        # Keep sorted.
        ":bls12_381",
        "//rs/crypto/internal/crypto_lib/bls12_381/type",
        "//rs/crypto/test_utils/reproducible_rng",
        "@crate_index//:criterion",
        "@crate_index//:rand",
    ],
)
